package com.bckj.fastboot.core.sql;

import java.util.Collection;
import java.util.Objects;

/**
 * SqlCondition
 *
 * @author wfc
 * @date 2025/11/14 15:05
 **/
public interface SqlCondition {

    boolean isSatisfiedBy(Object value);

    SqlCondition NOT_EMPTY = value -> {
        if (value == null) {
            return false;
        }
        if (value instanceof String str) {
            return !str.isEmpty();
        } else if (value instanceof Collection<?> coll) {
            return !coll.isEmpty();
        } else if (value instanceof Object[] arr) {
            return arr.length > 0;
        }
        return true;
    };

    SqlCondition NOT_BLANK = value -> {
        if (value == null) {
            return false;
        }
        if (value instanceof String str) {
            return !str.isBlank();
        } else if (value instanceof Collection<?> coll) {
            return !coll.isEmpty();
        } else if (value instanceof Object[] arr) {
            return arr.length > 0;
        }
        return true;
    };

    SqlCondition NOT_NULL = Objects::nonNull;
}
